/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.sbbs.disruptorlearn.longevent;

import com.lmax.disruptor.RingBuffer;
import java.nio.ByteBuffer;

/**
 *
 * @author Mr.fdc <fdc_messenger@126.com>
 */
public class LongEventProducer {

    private final RingBuffer<LongEvent> ringBuffer;

    public LongEventProducer(RingBuffer<LongEvent> ringBuffer) {
        this.ringBuffer = ringBuffer;
    }

    public void product(ByteBuffer bb) {
        long sequence = ringBuffer.next();  // Grab the next sequence  
        try {
            LongEvent event = ringBuffer.get(sequence); // Get the entry in the Disruptor  
            // for the sequence  
            event.set(bb.getLong(0));  // Fill with data  
        } finally {
            ringBuffer.publish(sequence);
        }
    }
}
